import Vue from 'vue'
export default {
  namespaced: true,
  state: () => {
    return {
      addressList: [],
    }
  },
  mutations: {
    addAddressMut(state, { content, editnum }) {
      if (content.isDefault) {
        state.addressList.forEach(item => {
          item.isDefault = false
        })
      }
      if (editnum != -1) {
        state.addressList[editnum] = content
        return
      }
      else {
        state.addressList.push(content)
      }
    },
    delAddressMut(state, content) {
      var length = state.addressList.length;
      for (var i = 0; i < length; i++) {
        if (state.addressList[i].address == content.address&&state.addressList[i].address == content.address&&state.addressList[i].tel == content.tel) {
          state.addressList.splice(i, 1); //删除下标为i的元素  
          console.log(state.addressList);
        }
      }
    },
    defaultAddressMut(state, d) {
      state.addressList.forEach(item => {
        item.isDefault = false
      })
      state.addressList[d].isDefault = true
    }


  }
}